import 'package:flutter_demo3/entity/news_entity.dart';

newsEntityFromJson(NewsEntity data, Map<String, dynamic> json) {
	if (json['data'] != null) {
		data.data = new List<NewsData>();
		(json['data'] as List).forEach((v) {
			data.data.add(new NewsData().fromJson(v));
		});
	}
	if (json['success'] != null) {
		data.success = json['success'];
	}
	if (json['massage'] != null) {
		data.massage = json['massage']?.toString();
	}
	return data;
}

Map<String, dynamic> newsEntityToJson(NewsEntity entity) {
	final Map<String, dynamic> data = new Map<String, dynamic>();
	if (entity.data != null) {
		data['data'] =  entity.data.map((v) => v.toJson()).toList();
	}
	data['success'] = entity.success;
	data['massage'] = entity.massage;
	return data;
}

newsDataFromJson(NewsData data, Map<String, dynamic> json) {
	if (json['id'] != null) {
		data.id = json['id']?.toInt();
	}
	if (json['title'] != null) {
		data.title = json['title']?.toString();
	}
	if (json['userId'] != null) {
		data.userId = json['userId']?.toInt();
	}
	if (json['imgUrl'] != null) {
		data.imgUrl = json['imgUrl']?.toString();
	}
	if (json['content'] != null) {
		data.content = json['content']?.toString();
	}
	if (json['likesNum'] != null) {
		data.likesNum = json['likesNum']?.toInt();
	}
	if (json['commentNum'] != null) {
		data.commentNum = json['commentNum']?.toInt();
	}
	if (json['forwardingNum'] != null) {
		data.forwardingNum = json['forwardingNum']?.toInt();
	}
	if (json['date'] != null) {
		data.date = json['date']?.toString();
	}
	return data;
}

Map<String, dynamic> newsDataToJson(NewsData entity) {
	final Map<String, dynamic> data = new Map<String, dynamic>();
	data['id'] = entity.id;
	data['title'] = entity.title;
	data['userId'] = entity.userId;
	data['imgUrl'] = entity.imgUrl;
	data['content'] = entity.content;
	data['likesNum'] = entity.likesNum;
	data['commentNum'] = entity.commentNum;
	data['forwardingNum'] = entity.forwardingNum;
	data['date'] = entity.date;
	return data;
}